<template>
  <div class="login">
    <img class="logo" :src="Images.logo" alt="">
    <div class="login-body login">
      <van-form @submit="onSubmit">
        <van-field
          v-model="userName"
          name="username"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <div class="switch-submit-type" @click="switchOperationType">去{{computeOperationName}}</div>
          <van-button round block color="#1baeae" native-type="submit">{{computeOperationName}}</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script lang="ts">
import { ref, reactive, toRefs, onMounted, watch, computed } from 'vue'
import useUserLogin from '../../composables/useUserLogin'
import useImages from '../../composables/useImages'
import { UserInfoType } from '../../types/common'

export default {
  setup() {
    const userInfoState = reactive<UserInfoType>({
      userName: '',
      password: ''
    })

    onMounted(() => {
      console.log('onMounted')
    })

    const { Images } = useImages()
    const { operationType, switchOperationType, onSubmit } = useUserLogin(userInfoState)
    const computeOperationName = computed(() => operationType.value === 'login' ? '登录': '注册')
    
    return {
      ...toRefs<UserInfoType>(userInfoState),
      Images,
      onSubmit,
      switchOperationType,
      computeOperationName
    }
  },
}
</script>

<style lang="less">
  .login {
    .logo {
      width: 120px;
      height: 120px;
      display: block;
      margin: 80px auto 20px;
    }
    .login-body {
      padding: 0 20px;
    }
    .switch-submit-type {
      font-size: 14px;
      float: right;
      margin-bottom: 20px;
      color: #1989fa;
      display: inline-block;
    }
    .verify-bar-area {
      margin-top: 24px;
      .verify-left-bar {
        border-color: #1baeae;
      }
      .verify-move-block {
        background-color: #1baeae;
        color: #fff;
      }
    }
    .verify {
      >div {
        width: 100%;
      }
      display: flex;
      justify-content: center;
      .cerify-code-panel {
        margin-top: 16px;
      }
      .verify-code {
        width: 40%!important;
        float: left!important;
      }
      .verify-code-area {
        float: left!important;
        width: 54%!important;
        margin-left: 14px!important;
        .varify-input-code {
          width: 90px;
          height: 38px!important;
          border: 1px solid #e9e9e9;
          padding-left: 10px;
          font-size: 16px;
        }
        .verify-change-area {
          line-height: 44px;
        }
      }
    }
  }
</style>

